<?php
namespace Common\Model;
use Think\Model;
use Common\Model\VRLiveModel;
class LiveResourcesModel extends VRLiveModel
{
	
	protected $_validate = array(
	);
	
	
	function getResourcesList($formParam, $pageStart, $pageSize){
		$resultData = array();
		$where = array();
		$admin_user_model = M('vradmin1.user','admin_');
		$where['status'] = '1';
		if($formParam['Name']) $where['name'] = array('EQ',$formParam['Name']);
		if(isset($formParam['creatorName'])){
			if($formParam['creatorName']){
				$admin_user_info = $admin_user_model->where('real_name like "%'.$formParam['creatorName'].'%" ')->find();
				if($admin_user_info){
					$where['creator_id'] = array('EQ',$admin_user_info['admin_id']);
				}else{
					$where['creator_id'] = '-1';
				}
			}
		}
		if($formParam['Type']) $where['type'] = array('EQ',$formParam['Type']);
		if($formParam['startDate']) $where['create_time'] =array('egt',$formParam['startDate']);
		if($formParam['endDate']) $where['create_time'] = array('elt',$formParam['endDate']);

		$count_Total = $this->where($where)->count();
		$resources_list = $this->where($where)
		->order("create_time desc, resource_id desc")
		->limit($pageStart, $pageSize)
		->select();

		foreach($resources_list as $key=>$value){
			$resources_list[$key]['creator_name'] = '';
			$real_name = $admin_user_model->where('admin_id = '.$value['creator_id'])->getField('real_name');
			if($real_name) $resources_list[$key]['creator_name'] = $real_name;
		} 
		$resultData['data'] = $resources_list;
		$resultData['count_Total'] = $count_Total;
		return $resultData;
	}
	
	
	//删除
	function resourcesDel($resource_id= null){
		if($resource_id){
			$data['status'] = 0;
			if(($this->where('resource_id = '.$resource_id)->data($data)->save()) !==false){
				return true;
			}
		}
		return false;
	}
	
	
}

